package org.evil.deus.rss;

import org.evil.deus.rss.provider.RSS;
import org.evil.deus.rss.settings.SettingsUtils;

import android.app.Application;
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;

public class Launcher extends Application {
	
	private class Initiator implements Runnable {
		public void run() {
			Cursor cursor = getContentResolver().query(RSS.Channel.CONTENT_URI, null, null, null, null);
			if (cursor.getCount() <= 0) {
				ContentValues values = new ContentValues();
				values.put(RSS.Channel.URL, getString(R.string.default_server_url));
				getContentResolver().insert(RSS.Channel.CONTENT_URI, values);
			}
			cursor.close();
			Intent intent = new Intent(getString(R.string.action_sync));
	        startService(intent);
		}
	}
	
	Thread thread = null;
	
	@Override
	public void onCreate() {
		super.onCreate();
		SettingsUtils.init(this);
		thread = new Thread(new Initiator());
		thread.start();
	}
}
